document.addEventListener('DOMContentLoaded', () => {
  const btn = document.getElementById('changeColorButton');
  btn?.addEventListener('click', async () => {
    try {
      const [tab] = await chrome.tabs.query({
        active: true,
        currentWindow: true,
      });
      if (!tab?.id) return;

      await chrome.scripting.executeScript({
        target: { tabId: tab.id },
        func: () => {
          document.documentElement.style.backgroundColor = 'green';
          if (document.body) {
            document.body.style.backgroundColor = 'green';
          }
        },
      });

      // 可选：执行完成后关闭弹窗
      // window.close();
    } catch (err) {
      console.error('Failed to change color:', err);
    }
  });
});